#!/bin/env bash
profile=160
src_root=/mecool/server
log_root=/mecool/logs
tomcat_root=/usr/local/tomcat7

cd $src_root
svn revert -R * >&/dev/null; svn up >&$log_root/svn.log

cd $src_root/mecool-main-core/src/main/resources
rm -f jdbc.properties; cp jdbc.$profile.properties jdbc.properties
cd $src_root/mecool-main-mobile/src/main/resources
rm -f web_config.txt; cp web_config.$profile.txt web_config.txt
rm -f logback.xml; cp logback.$profile.xml logback.xml
cd $src_root/mecool-main-web/src/main/resources
rm -f logback.xml; cp logback.$profile.xml logback.xml

cd $src_root/mecool
mvn clean package -Dmaven.test.skip=true >&$log_root/maven.log
if [ ! 0 = $? ]; then
	echo "*** maven compile error ***"
	exit 1
fi
$tomcat_root/bin/shutdown.sh >&/dev/null
sleep 3
cd $tomcat_root/webapps/
rm -rf dmsmobile.war
rm -rf dmsmobile
rm -rf dmsweb.war
rm -rf dmsweb
mv $src_root/mecool-main-web/target/dmsweb.war ./
mv $src_root/mecool-main-mobile/target/dmsmobile.war ./
$tomcat_root/bin/startup.sh >& /dev/null
